#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
int n;
unordered_map<int, int> rk;
vector<bool> added;
int ans;
int temp[50005];
void mergeSort(int nums[], int l, int r) {
    if (l >= r) return;
    int mid = l + (r - l) / 2;
    mergeSort(nums, l, mid);
    mergeSort(nums, mid + 1, r);
    int i = l, j = mid + 1;
    while (i <= mid && j <= r) {
        if (rk[nums[i]] > rk[nums[j]] && !added[nums[i]]) {
            ans++;
            added[nums[i]] = 1;
            j++;
            i++;
        } else
            i++;
    }
    i = l, j = mid + 1;
    int cur = l;
    while (i <= mid && j <= r) {
        if (rk[nums[j]] < rk[nums[i]])
            temp[cur++] = nums[j++];
        else
            temp[cur++] = nums[i++];
    }
    if (i == mid + 1)
        while (j <= r) temp[cur++] = nums[j++];
    else
        while (i <= mid) temp[cur++] = nums[i++];
    for (int t = l; t <= r; t++) nums[t] = temp[t];
}
int main() {
    cin >> n;
    added.resize(n + 1, 0);
    int cnt = 1;
    int name;
    for (int i = 0; i < n; i++) {
        cin >> name;
        rk[name] = cnt++;
    }
    int nums[n];
    for (int i = 0; i < n; i++) cin >> nums[i];
    mergeSort(nums, 0, n - 1);
    cout << ans << endl;
    return 0;
}

/*
    input:
    5
    5 4 3 2 1
    1 5 3 4 2

    output:
    2
 */